package com.sunny.netty.test;

import lombok.Data;

/**
 * @author sunny
 * @date 2018/12/10
 */
@Data
public class NutririonFacts {
    private final int servingSize;
    private final int servings;
    private final int calories;
    private final int fat;
    private final int sodium;
    private final int carbohydrate;

    private NutririonFacts(Builder builder) {
        servingSize = builder.servingSize;
        servings = builder.servings;
        calories = builder.calories;
        fat = builder.fat;
        sodium = builder.sodium;
        carbohydrate = builder.carbohydrate;
    }

    public static class Builder {
        private final int servingSize;
        private final int servings;

        private int calories = 0;
        private int fat = 0;
        private int sodium = 0;
        private int carbohydrate = 0;

        public Builder(int servingSize, int servings) {
            this.servingSize = servingSize;
            this.servings = servings;
        }

        public Builder calories(int calories) {
            this.calories = calories;
            return this;
        }
        public Builder fat(int fat) {
            this.fat = fat;
            return this;
        }
        public Builder sodium(int sodium) {
            this.sodium = sodium;
            return this;
        }
        public Builder carbohydrate(int carbohydrate) {
            this.carbohydrate = carbohydrate;
            return this;
        }

        public NutririonFacts build() {
            return new NutririonFacts(this);
        }
    }

}

class Test {
    public static void main(String[] args) {
        NutririonFacts.Builder builder = new NutririonFacts.Builder(1, 2);
        builder.calories(1);
        NutririonFacts build = builder.build();
        System.out.println(build);
    }
}
